package br.com.bringme.models.user;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import br.com.bringme.models.Pessoa;
import br.com.bringme.models.Telefone;

@Entity
@Table(name="bring_me.atendentes")
@SequenceGenerator(name = "atendentes_seq", sequenceName = "bring_me.atendentes_id_atendente_seq")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "permissao", discriminatorType=DiscriminatorType.STRING)
public abstract class Usuario extends Pessoa {

	@Id
	@Column(name = "id_atendente")
	@GeneratedValue(generator = "atendentes_seq", strategy = GenerationType.AUTO)
	protected Integer id;

	@OneToOne
	@JoinColumn(name = "permissao", insertable=false, updatable=false)
	private Permissao permissao;

	protected String login;

	protected String senha;

	@OneToMany(cascade = CascadeType.ALL)
	@JoinTable(name = "bring_me.usuarios_telefones", joinColumns = { @JoinColumn(name = "usuario") }, inverseJoinColumns = { @JoinColumn(name = "telefone") })
	protected Set<Telefone> telefones = new HashSet<Telefone>();

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Permissao getPermissao() {
		return permissao;
	}

	public void setPermissao(Permissao permissao) {
		this.permissao = permissao;
	}

	public String getLogin() {
		return login;
	}

	public void setLogin(String login) {
		this.login = login;
	}

	public String getSenha() {
		return senha;
	}

	public void setSenha(String senha) {
		this.senha = senha;
	}

	public Set<Telefone> getTelefones() {
		return telefones;
	}

	public void setTelefones(Set<Telefone> telefones) {
		this.telefones = telefones;
	}

}
